package com.link2room.rodimus.controller.api;

import com.link2room.common.dto.result.base.BaseResultDto;
import com.link2room.common.util.StringUtil;
import com.link2room.rodimus.dto.param.api.SalesmanApiParamDto;
import com.link2room.rodimus.dto.result.base.SalesmanBaseInfoDto;
import com.link2room.rodimus.entity.SalesmanBase;
import com.link2room.rodimus.facade.ISalesmanApiFacadeService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * Created by VegetaKo on 2016/9/21.
 */
@RestController
@RequestMapping("/api/Salesmans")
@Deprecated /* 去ticket */
public class SalesmanApiController {

    @Resource
    private ISalesmanApiFacadeService salesmanFacadeService;

    @RequestMapping(method = RequestMethod.POST)
    public BaseResultDto NewSalesman(
            @RequestBody SalesmanApiParamDto salesmanApiParamDto
    ) throws Exception {
        BaseResultDto res = new BaseResultDto();
        //MemberInfoDto memberInfoDto = new MemberInfoDto();
        salesmanFacadeService.saveSalesman(salesmanApiParamDto);
        SalesmanBase salesmanBase = salesmanFacadeService.getSalesman(salesmanApiParamDto);
        res.setResultCode(0);
        res.setResultInfo(salesmanBase );

        return res;
    }

    @RequestMapping(method = RequestMethod.PUT)
    public BaseResultDto ModifySalesman(
            @RequestBody SalesmanApiParamDto salesmanApiParamDto
    ) throws Exception {
        BaseResultDto res = new BaseResultDto();
        salesmanFacadeService.modifySalesman(salesmanApiParamDto);
        res.setResultCode(0);
        return res;
    }

    @RequestMapping(value = "/{ticket}",method = RequestMethod.GET)
    public BaseResultDto GetSalesman() throws Exception {
        BaseResultDto res = new BaseResultDto();
        SalesmanApiParamDto salesmanApiParamDto = new SalesmanApiParamDto();
        SalesmanBase salesmanBase = salesmanFacadeService.getSalesman(salesmanApiParamDto);
        res.setResultInfo(salesmanBase);
        res.setResultCode(0);
        return res;
    }
    @RequestMapping(value = "/currentSalesman",method = RequestMethod.GET)
    public BaseResultDto getCurrentSalesman() throws Exception {
        BaseResultDto res = new BaseResultDto();
        SalesmanApiParamDto salesmanApiParamDto = new SalesmanApiParamDto();
        SalesmanBaseInfoDto salesmanBase = salesmanFacadeService.getCurrentSalesmanBaseInfo(salesmanApiParamDto);
        res.setResultInfo(salesmanBase);
        res.setResultCode(0);
        return res;
    }


    @RequestMapping(value = "/{ticket}/IncomeDetails", method = RequestMethod.GET)
    public BaseResultDto GetIncomeDetails(
            @RequestParam(name = "awardSta",required = false)String awardSta
    ) throws Exception {
        BaseResultDto res = new BaseResultDto();
        SalesmanApiParamDto salesmanApiParamDto = new SalesmanApiParamDto();
        if( StringUtil.isNotBlank(awardSta )){
            salesmanApiParamDto.setAwardSta(awardSta );
        }
        res.setResultInfo(salesmanFacadeService.getSalesmanIncomeDetails(salesmanApiParamDto));
        res.setResultCode(0);
        return res;

    }
    @RequestMapping(value = "/{ticket}/SalesmanMembers", method = RequestMethod.GET)
    public BaseResultDto GetSalesmanMember() throws Exception {
        BaseResultDto res = new BaseResultDto();
        SalesmanApiParamDto salesmanApiParamDto = new SalesmanApiParamDto();
        res.setResultInfo(salesmanFacadeService.getSalesmanMembers(salesmanApiParamDto));
        res.setResultCode(0);
        return res;

    }
}
